package com.binance.zkconfig.config;

import com.binance.zkconfig.app.archainus.ArchaiusConfig;
import com.binance.zkconfig.app.listener.ApplicationReadyListener;
import com.binance.zkconfig.app.util.ZkConfigUtils;
import com.binance.zkconfig.app.watcher.ZkConfigWatcher;
import com.binance.zkconfig.config.condition.EnableZkConfigCondition;
import com.binance.zkconfig.processor.ZkPropertySourcesProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * Created by Fei.Huang on 2018/8/29.
 */
@Configuration
@Conditional(EnableZkConfigCondition.class)
public class ZkConfiguration {

    @Bean
    ArchaiusConfig archaiusConfiguration() {
        return new ArchaiusConfig();
    }

    @Bean
    ZkConfigWatcher zkConfigWatcher() {
        return new ZkConfigWatcher(ZkPropertySourcesProcessor.getZkConfigNodes(), ZkConfigUtils.getCuratorFramework(null));
    }

    @Bean
    ApplicationReadyListener applicationReadyListener() {
        return new ApplicationReadyListener();
    }
}